﻿@{
    ViewData["Title"] = "首页";
}

@if (ViewBag.Error != null)
{
    <div class="layui-card">
        <div class="layui-card-header">
            <h2><i class="layui-icon layui-icon-close-fill"></i> 数据库连接错误</h2>
        </div>
        <div class="layui-card-body">
            <div class="layui-text" style="color: #cf1322; padding: 20px; text-align: center;">
                <i class="layui-icon layui-icon-close-fill" style="font-size: 48px;"></i>
                <h3>无法连接到数据库</h3>
                <p>错误信息: @ViewBag.Error</p>
                <p>请检查数据库连接字符串配置</p>
            </div>
        </div>
    </div>
}
else
{
    <div class="layui-row layui-col-space15">
        <!-- 系统概览卡片 -->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h2><i class="layui-icon layui-icon-home"></i> 系统概览</h2>
                </div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-md3">
                            <div class="layui-card" style="text-align: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
                                <div class="layui-card-body">
                                    <i class="layui-icon layui-icon-log" style="font-size: 48px; margin-bottom: 10px;"></i>
                                    <h3>@ViewBag.TotalLogs</h3>
                                    <p>总日志数</p>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-card" style="text-align: center; background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: white;">
                                <div class="layui-card-body">
                                    <i class="layui-icon layui-icon-app" style="font-size: 48px; margin-bottom: 10px;"></i>
                                    <h3>@ViewBag.TotalProjects</h3>
                                    <p>项目数量</p>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-card" style="text-align: center; background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); color: white;">
                                <div class="layui-card-body">
                                    <i class="layui-icon layui-icon-chart" style="font-size: 48px; margin-bottom: 10px;"></i>
                                    <h3>@ViewBag.TodayLogs</h3>
                                    <p>今日日志</p>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-card" style="text-align: center; background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); color: white;">
                                <div class="layui-card-body">
                                    <i class="layui-icon layui-icon-util" style="font-size: 48px; margin-bottom: 10px;"></i>
                                    <h3>@ViewBag.ErrorLogs</h3>
                                    <p>错误日志</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 快速操作 -->
        <div class="layui-col-md6">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h3><i class="layui-icon layui-icon-util"></i> 快速操作</h3>
                </div>
                <div class="layui-card-body">
                    <div class="layui-btn-group layui-btn-group-vertical" style="width: 100%;">
                        <a href="/LogManager" class="layui-btn layui-btn-lg layui-btn-primary" style="width: 100%; margin-bottom: 10px;">
                            <i class="layui-icon layui-icon-search"></i> 查询日志
                        </a>
                        <a href="/Project" class="layui-btn layui-btn-lg layui-btn-normal" style="width: 100%; margin-bottom: 10px;">
                            <i class="layui-icon layui-icon-app"></i> 项目管理
                        </a>
                        <a href="/Project/Create" class="layui-btn layui-btn-lg layui-btn-warm" style="width: 100%; margin-bottom: 10px;">
                            <i class="layui-icon layui-icon-add-1"></i> 新增项目
                        </a>
                        <a href="/LogManager" class="layui-btn layui-btn-lg layui-btn-primary" style="width: 100%;">
                            <i class="layui-icon layui-icon-search"></i> 查看日志
                        </a>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 最近日志 -->
        <div class="layui-col-md6">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h3><i class="layui-icon layui-icon-time"></i> 最近日志</h3>
                </div>
                <div class="layui-card-body">
                    @if (ViewBag.RecentLogs != null && ((IEnumerable<dynamic>)ViewBag.RecentLogs).Any())
                    {
                        foreach (var log in ViewBag.RecentLogs)
                        {
                            <div class="layui-row" style="margin-bottom: 10px; padding: 10px; border-bottom: 1px solid #f0f0f0;">
                                <div class="layui-col-md8">
                                    <div style="font-weight: bold;">@log.ServerCode - @log.Code</div>
                                    <div style="color: #666; font-size: 12px;">@log.Message</div>
                                </div>
                                <div class="layui-col-md4" style="text-align: right;">
                                    <span class="layui-badge @(log.Level >= 4 ? "layui-bg-red" : log.Level >= 3 ? "layui-bg-orange" : "layui-bg-blue")">Level @log.Level</span>
                                    <div style="font-size: 12px; color: #999; margin-top: 5px;">@log.CreateTime.ToString("MM-dd HH:mm")</div>
                                </div>
                            </div>
                        }
                    }
                    else
                    {
                        <div class="layui-text" style="text-align: center; color: #999; padding: 20px;">暂无日志数据</div>
                    }
                </div>
            </div>
        </div>
        
        <!-- 项目状态 -->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h3><i class="layui-icon layui-icon-app"></i> 项目状态</h3>
                </div>
                <div class="layui-card-body">
                    @if (ViewBag.Projects != null && ((IEnumerable<dynamic>)ViewBag.Projects).Any())
                    {
                        <div class="layui-row layui-col-space15">
                            @foreach (var project in ViewBag.Projects)
                            {
                                <div class="layui-col-md4">
                                    <div class="layui-card" style="text-align: center;">
                                        <div class="layui-card-body">
                                            <h4>@project.AppName</h4>
                                            <span class="layui-badge @(project.Status==1 ? "layui-bg-green" : "layui-bg-gray")">@(project.Status==1 ? "启用" : "禁用")</span>
                                            <div style="margin-top: 10px;">
                                                <span class="layui-badge layui-bg-blue">@project.AppCode</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            }
                        </div>
                    }
                    else
                    {
                        <div class="layui-text" style="text-align: center; color: #999; padding: 20px;">暂无项目数据</div>
                    }
                </div>
            </div>
        </div>
    </div>
}

@section Scripts {
    <script>
        layui.use(['layer', 'element'], function(){
            var layer = layui.layer;
            var element = layui.element;
            
        });
    </script>
}
